package cn.kgc.api.service.impl;

import cn.kgc.api.entity.Users;
import cn.kgc.api.mapper.DeptsMapper;
import cn.kgc.api.mapper.UsersMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.api.service.UsersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;


@Slf4j
@Service("usersService")
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    @Resource
    private DeptsMapper deptsMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean update(Users users) {
        //更新用户信息
        this.updateById(users);
        //更新部门中的此用户信息
        deptsMapper.updateDeptUserInfo(
                users.getUserName(),
                users.getUserEmail(),
                Integer.parseInt(users.getUserId())
        );
        return true;
    }
}
